package com.kingyun.gpsinspection.purificationservice.services.activitiservice.ext.personrule;

import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.kingyun.gpsinspection.purificationservice.common.activiti.ActivitiConstants;
import com.kingyun.gpsinspection.purificationservice.facade.model.activiti.BpmConfNode;
import com.kingyun.gpsinspection.purificationservice.services.activitiservice.ext.exception.AssignException;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;

/**
 * 会签配置规则
 * @author zjh
 * @since 20170615
 */
public class MultiRule implements Rule {


    private static MultiRule multiRule;

    private MultiRule(){};

    public static MultiRule getInstance(){
        if(multiRule==null){
            multiRule=new MultiRule();
        }
        return multiRule;
    }

    @Override
    public void assigneRule(ActivityExecution execution, TaskEntity task, BpmConfNode bpmConfUser) {
        //流程平台配置
        if(Strings.isNullOrEmpty(bpmConfUser.getUserValue())){
            throw new AssignException("会签没有相关办理人");
        }
        String[] multiInstanceUsers = bpmConfUser.getUserValue().split(ActivitiConstants.PERON_SEPARATE);
        execution.setVariable(ActivitiConstants.MUTIL_USERS, Lists.newArrayList(multiInstanceUsers));
    }
}
